package cn.edu.neusoft.yuejian4.yuejian_4.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.yuejian4.yuejian_4.Config.Server;
import cn.edu.neusoft.yuejian4.yuejian_4.R;
import cn.edu.neusoft.yuejian4.yuejian_4.activity.ClubDetailActivity;
import cn.edu.neusoft.yuejian4.yuejian_4.activity.TrainDetailActivity;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.Club;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.Train;

/**
 * Created by Lix on 2018/10/9.
 */

public class ClubListAdapter extends RecyclerView.Adapter<ClubListAdapter.ViewHolder>{

    private List<Club> mClubList;
    private Context mContext;

    public ClubListAdapter(Context mContext, List<Club> mClubList){
        this.mContext = mContext;
        this.mClubList = mClubList;
        //mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public ClubListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.club_cardview,parent,false);
        ClubListAdapter.ViewHolder holder = new ClubListAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ClubListAdapter.ViewHolder holder, int position) {
        final Club club = mClubList.get(position);
        Picasso.with(mContext)
                .load(Server.PIC_URL_J+club.getPic())
                .placeholder(R.drawable.ic_default_img)
                .memoryPolicy(MemoryPolicy.NO_CACHE)
                .into(holder.clubImg);
        holder.clubName.setText(club.getClub_name());
        holder.clubImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, ClubDetailActivity.class);
                intent.putExtra("clubid",club.getId());
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mClubList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView clubImg;
        TextView clubName;
        LinearLayout club_container;

        public ViewHolder(View view){
            super(view);
            clubImg= (ImageView)view.findViewById(R.id.club_img);
            clubName = (TextView)view.findViewById(R.id.club_name);
            club_container = (LinearLayout)view.findViewById(R.id.club_container);
        }
    }
}


